import numpy as np

# 给定的数组
Z = np.array([[0, 1, 2, 3], [4, 5, 6, 7]])

# 给定的值
z = 5.1

# 计算差的绝对值
diff = np.abs(Z - z)

# 找到最小差的索引
index_of_closest = np.unravel_index(np.argmin(diff), diff.shape)

# 获取最接近的数
closest_value = Z[index_of_closest]

print(f"The closest value to {z} in the array is {closest_value} at position {index_of_closest}")